package jhta;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.table.DefaultTableModel;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JSeparator;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.DefaultComboBoxModel;

public class MemberInput extends JInternalFrame {
	SimpleDateFormat sdf;
	JavaDBConnection jdbc;
	Connection conn;

	Main mn;
	int count = 0;

	DefaultTableModel model = null;
	Vector headers = new Vector();// jtable
	Vector data = new Vector();// 엑셀파일데이터
	JFileChooser jChooser;
	File file;
	Workbook workbook = null;

	boolean flag = true;
	int tableWidth = 0;
	int tableHeight = 0;

	String fileName = "noname"; // 사진 저장을 위한 경로를 만들어주기 위해서
	String folder = "img\\logo\\"; // 이미지를 저장할 경로 폴더 설정을 위해서

	private JTabbedPane tabbedPane;
	private JPanel student;
	private JPanel manager;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JTextField inputSname;
	private JButton button;
	private JPanel panel_2;
	private JTextField inputScode;
	private JButton btnWjwkd;
	private JPanel panel_4;
	private JTextField inputMph1;
	private JLabel label;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JTextField inputMname;
	private JTextField inputMcode;
	private JButton btn_Mok;
	private JButton btn_Mcancel;
	private JLabel txtLogo2;
	private JButton btn_Add;
	private JPanel panel_5;
	private JLabel label_6;
	private JLabel label_7;
	private JTextField inputSdate;
	private JComboBox cb_Scodename;
	private JComboBox cb_rgname;
	private JButton button_2;
	private JButton button_3;

	private JTextField inputMph2;
	private JTextField inputMph3;
	private JLabel lblNewLabel_4;
	private JLabel label_4;
	private JPanel panel_6;
	private JPanel panel_8;
	private JLabel label_13;
	private JTextField inputSph1;
	private JLabel label_14;
	private JTextField inputSph2;
	private JLabel label_15;
	private JTextField inputSph3;
	private JPanel panel_9;
	private JPasswordField inputMpassword;
	private JLabel label_11;
	private JLabel label_12;
	private JLabel label_8;
	private JPanel panel_7;
	private JLabel txtLogo1;
	private JButton button_4;
	private JPanel panel_3;
	private JButton btnExcel;
	private JPanel panel_10;
	private JScrollPane scrollPane;
	private JTable table;
	private JButton btnNewButton;
	private JButton btnFS;
	private JPanel panel;
	private JLabel lblstatus;
	private JButton button_1;

	public MemberInput(Main m) {

		super("회원및 관리자 입력", true, true, true, false);

		getContentPane().setBackground(SystemColor.inactiveCaptionBorder);
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameActivated(InternalFrameEvent arg0) {
				cb_Name();
				cb_rgname();

			}

			@Override
			public void internalFrameClosing(InternalFrameEvent arg0) {
				mn.mInput = null;
			}
		});
		setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 478, 335);
		getContentPane().setLayout(null);
		getContentPane().add(getTabbedPane());
		getContentPane().add(getInputSdate());
		getContentPane().add(getLabel_8_1());
		this.mn = m;

		jdbc = new JavaDBConnection();
		conn = jdbc.getConn();

		reSet();
		setDate();


	}

	// ---------------공통---------------------
	public void setDate() {// 등록일
		sdf = new SimpleDateFormat("yyyy-MM-dd");
		String a = sdf.format((new Date()));
		inputSdate.setText(a);

	}

	public void reSet() {// 초기화
		// 관리자
		inputMname.setText("");
		inputMph1.setText("");
		inputMph2.setText("");
		inputMph3.setText("");
		inputMpassword.setText("");

		// 수강생
		inputSname.setText("");
		inputSph1.setText("");
		inputSph2.setText("");
		inputSph3.setText("");

		lblstatus.setText("");

	}

	// ---------------관리자--------------------------------
	public boolean numberEx() {// 전화번호 예외처리
		try {

			int a = Integer.parseInt(inputMph1.getText());
			int b = Integer.parseInt(inputMph2.getText());
			int c = Integer.parseInt(inputMph3.getText());

			return true;
		} catch (Exception e) {
		}
		return false;
	}

	public boolean Memexcept() {
		String sql = "select distinct m.name from bookmember m left outer join code c on m.code_no= c.code_no where c.code_name='관리자' order by m.name asc";
		try {
			PreparedStatement pst1 = conn.prepareStatement(sql);
			ResultSet rs = pst1.executeQuery();
			System.out.println(rs);
			while (rs.next()) {

				if (rs.getString(1).equals(inputMname.getText())) {
					JOptionPane.showMessageDialog(null,
							"중복된 성명은 입력할 수 없습니다. 다른 성명을 입력해주세요.");
					return true;
				}
			}
		} catch (Exception e) {
			e.getStackTrace();
		}
		return false;
	}

	public String pw() {// 패스워드
		String k = "";
		char[] pw = inputMpassword.getPassword();
		for (int i = 0; i < pw.length; i++) {
			k += pw[i];

		}
		return k;
	}

	public void MemInsert1() {// 관리자입력

		try {
			char[] a = inputMpassword.getPassword();
			String irum = inputMname.getText();
			String ph = inputMph1.getText() + "-" + inputMph2.getText() + "-"
					+ inputMph3.getText();

			String sql1 = "insert into bookmember (no,name,phone,password,code_no) values (seq_mem_no.nextval,?,?,?,(select code_no from code where code_name='관리자' and code_small is null))";
			PreparedStatement pst1 = conn.prepareStatement(sql1);
			pst1.setString(1, irum);
			pst1.setString(2, ph);
			pst1.setString(3, pw());

			pst1.executeUpdate();
			pst1.close();

		} catch (Exception ex) {
			ex.getStackTrace();

		}
	}

	// (예외처리)확인버튼
	private JButton getBtn_Mok() {
		if (btn_Mok == null) {
			btn_Mok = new JButton("저장");
			btn_Mok.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					if (!Memexcept()) {
						if (inputMname.getText().equals("")) {
							JOptionPane.showMessageDialog(null, "이름을 입력해주세요!");

						} else if (inputMph1.getText().equals("")
								|| inputMph2.getText().equals("")
								|| inputMph3.getText().equals("")) {
							JOptionPane.showMessageDialog(null,
									"전화번호의 빈칸을 모두 입력해주세요.");
						} else if (!numberEx()) {
							JOptionPane.showMessageDialog(null,
									"전화번호는 숫자만 입력해주세요!");

						} else if (pw().equals("")) {
							JOptionPane.showMessageDialog(null, "암호를 입력해주세요!");

						} else {
							int a = JOptionPane.showConfirmDialog(null,
									"저장하시겠습니까?");
							if (a == JOptionPane.OK_OPTION) {
								MemInsert1();

								if (mn.mUpdate != null)
									mn.mUpdate.MemSearch();

								reSet();
								JOptionPane
										.showMessageDialog(null, "잘저장되었습니다.");

							}
						}
					}

				}
			});
			btn_Mok.setBounds(265, 181, 56, 40);
		}
		return btn_Mok;
	}

	// -----------------------수강생-------------------
	public boolean numberEx2() {// (예외처리)전화번호
		try {
			int a = Integer.parseInt(inputSph1.getText());
			int b = Integer.parseInt(inputSph2.getText());
			int c = Integer.parseInt(inputSph3.getText());
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	public void cb_rgname() {// 수강생>>등록자 콤보박스
		try {

			String rgname = "select name from bookmember where password is not null order by name";

			PreparedStatement pst3 = conn.prepareStatement(rgname);

			ResultSet rs = pst3.executeQuery();

			while (rs.next()) {

				cb_rgname.addItem(rs.getString(1));

			}
			rs.close();
			pst3.close();

		} catch (Exception rg) {
			rg.getStackTrace();
		}
	}

	public void cb_Name() {// 수강생>>기수 콤보박스
		try {

			String cn = "select distinct code_name from code where code_small like 'B%' and code_Big ='A3'";

			PreparedStatement pst4 = conn.prepareStatement(cn);
			ResultSet rs = pst4.executeQuery();

			while (rs.next()) {

				cb_Scodename.addItem(rs.getString(1));

			}
			rs.close();
			pst4.close();

		} catch (Exception rg) {
			rg.getStackTrace();
		}
	}

	public void MemInsert2() {// 수강생입력

		try {
			String irum = inputSname.getText();// 이름
			String ph = inputSph1.getText() + "-" + inputSph2.getText() + "-"
					+ inputSph3.getText();// 연락처
			String mn = cb_rgname.getSelectedItem().toString();// 등록자(콤보박스에서 선택된
																// 이름)
			String cn = cb_Scodename.getSelectedItem().toString();// 기수(콤보박스에서
																	// 선택된 과정명)
			String sql2 = "insert into bookmember (no,name,phone,rno,code_no) values (seq_mem_no.nextval,?,?,(select no from bookmember where name=?),(select code_no from code where code_name=? and code_big='A3'))";

			PreparedStatement pst2 = conn.prepareStatement(sql2);
			pst2.setString(1, irum);
			pst2.setString(2, ph);
			pst2.setString(3, mn);
			pst2.setString(4, cn);

			pst2.executeUpdate();
			pst2.close();

		} catch (Exception ex) {
			ex.getStackTrace();
		}
	}

	// (예외처리)수강생 정보의 확인
	private JButton getBtnWjwkd() {
		if (btnWjwkd == null) {
			btnWjwkd = new JButton("저장");
			btnWjwkd.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					if (inputSname.getText().equals("")) {
						JOptionPane.showMessageDialog(null, "이름을 입력해주세요!");

					} else if (inputSph1.getText().equals("")
							|| inputSph2.getText().equals("")
							|| inputSph3.getText().equals("")) {
						JOptionPane.showMessageDialog(null,
								"전화번호의 빈칸을 모두 입력해주세요.");

					} else if (!numberEx2()) {
						JOptionPane
								.showMessageDialog(null, "전화번호는 숫자만 입력해주세요.");

					} else {
						int a = JOptionPane
								.showConfirmDialog(null, "저장하시겠습니까?");
						if (a == JOptionPane.OK_OPTION) {
							MemInsert2();
							mn.mUpdate.MemSearch();
							JOptionPane.showMessageDialog(null, "잘저장되었습니다.");
							reSet();

						}
					}

				}
			});
			btnWjwkd.setBounds(245, 177, 56, 40);
		}
		return btnWjwkd;
	}

	// ------------------Excel to jTable------------------
	public void exam() {
		jChooser = new JFileChooser();
		jChooser.showOpenDialog(null);

		File file = jChooser.getSelectedFile();
		if (!file.getName().endsWith("xls")) {
			JOptionPane
					.showMessageDialog(
							null,
							"MicroSoft Office Excel 2007 Version이하의  확장자명 .xls 파일만 지원합니다.",
							"Error", JOptionPane.ERROR_MESSAGE);
		} else {
			fillData(file);
			model = new DefaultTableModel(data, headers);
			tableWidth = model.getColumnCount() * 150;
			tableHeight = model.getRowCount() * 25;
			table.setPreferredSize(new Dimension(tableWidth, tableHeight));
			table.setModel(model);

		}
		getTable();
		model = new DefaultTableModel(data, headers);
		table.setModel(model);
		tableWidth = model.getColumnCount() * 50;
		tableHeight = model.getRowCount() * 25;
		table.setPreferredSize(new Dimension(tableWidth, tableHeight));
		getScrollPane();

	}

	public void fillData(File file) {
		count = 0;
		try {
			try {
				workbook = workbook.getWorkbook(file);

			} catch (IOException ex) {
				Logger.getLogger(MemberInput.class.getName()).log(Level.SEVERE,
						null, ex);
			}
			Sheet sheet = workbook.getSheet(0);

			headers.clear();
			for (int i = 0; i < sheet.getColumns(); i++) {
				Cell cell1 = sheet.getCell(i, 0);
				headers.add(cell1.getContents());
			}

			data.clear();

			for (int j = 1; j < sheet.getRows(); j++) {
				Vector d = new Vector();
				for (int i = 0; i < sheet.getColumns(); i++) {
					Cell cell = sheet.getCell(i, j);
					d.add(cell.getContents());
				}
				d.add("\n");
				data.add(d);
				count++;
			}
		} catch (BiffException e) {
			e.printStackTrace();
		}
	}

	public void exinsert() {// --삽입

		try {
			for (int i = 0; i < count; i++) {
				String ir = (String) table.getValueAt(i, 0);
				String ph = (String) table.getValueAt(i, 1);// 전화번호
				String rir = cb_rgname.getSelectedItem().toString();
				String cno = cb_Scodename.getSelectedItem().toString();

				String sql2 = "insert into bookmember (no,name,phone,rno,code_no) values(seq_mem_no.nextval,?,?,(select no from bookmember where name=?),(select code_no from code where code_name=? and code_big='A3'))";// 하나씩
																																																							// 저장하기

				PreparedStatement pst = conn.prepareStatement(sql2);

				pst.setString(1, ir);
				pst.setString(2, ph);
				pst.setString(3, rir);
				pst.setString(4, cno);

				pst.executeUpdate();
				pst.close();

			}
		} catch (Exception e) {
			e.getStackTrace();
		}

	}

	// Excel불러오기 버튼
	private JButton getBtnExcel() {
		if (btnExcel == null) {
			btnExcel = new JButton("엑셀 파일 불러오기");
			btnExcel.setBounds(245, 222, 160, 30);
			btnExcel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					exam();
					lblstatus.setText("엑셀파일의 데이터 " + count + " 개가 선택되었습니다.");
					if (true) {
						setBounds(getX(), getY(), 488, 700);
					}

				}
			});
		}
		return btnExcel;
	}

	// 접기 버튼
	public void foldbtn() {
		setBounds(getX(), getY(), 478, 335);
	}

	// 펴기 버튼
	public void spreadbtn() {
		setBounds(getX(), getY(), 478, 700);
	}

	private JButton getBtnFS() {
		if (btnFS == null) {
			btnFS = new JButton("");
			btnFS.setContentAreaFilled(false);
			btnFS.setOpaque(false);
			btnFS.setBorder(null);
			btnFS.setBackground(Color.WHITE);
			btnFS.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\down.png"));
			btnFS.setBounds(412, 222, 35, 35);
			btnFS.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {

					if (flag) {
						btnFS.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\up.png"));
						spreadbtn();
						flag = false;
					} else {
						btnFS.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\down.png"));
						foldbtn();
						flag = true;
					}

				}
			});
		}
		return btnFS;
	}

	// ---------------------사진----------------------------------
	public void logo() {// 로고 이미지 수정
		try {
			JFileChooser fc = new JFileChooser();
			int yn = fc.showOpenDialog(this);
			if (yn == JFileChooser.APPROVE_OPTION) {
				File f = fc.getSelectedFile();
				fileName = f.getPath();

				// 이미지를 가져온 후 그 이미지의 사이즈를 조정해서 셋팅
				Image imagetemp = new ImageIcon(fileName).getImage(); // 이미지생성
				Image image = imagetemp.getScaledInstance(100, 100,
						Image.SCALE_SMOOTH); // 이미지리사이즈
				ImageIcon icontemp = new ImageIcon(image); // 리사이즈된 이미지아이콘생성
				txtLogo2.setText("");
				txtLogo2.setIcon(icontemp);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public void logo2() {// 로고 이미지 수정
		try {
			JFileChooser fc = new JFileChooser();
			int yn = fc.showOpenDialog(this);
			if (yn == JFileChooser.APPROVE_OPTION) {
				File f = fc.getSelectedFile();
				fileName = f.getPath();

				// 이미지를 가져온 후 그 이미지의 사이즈를 조정해서 셋팅
				Image imagetemp = new ImageIcon(fileName).getImage(); // 이미지생성
				Image image = imagetemp.getScaledInstance(100, 100,
						Image.SCALE_SMOOTH); // 이미지리사이즈
				ImageIcon icontemp = new ImageIcon(image); // 리사이즈된 이미지아이콘생성
				txtLogo1.setText("");
				txtLogo1.setIcon(icontemp);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}


	private JButton getBtn_Mcancel() {
		if (btn_Mcancel == null) {
			btn_Mcancel = new JButton("닫기");
			btn_Mcancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					reSet();
					setVisible(false);
				}
			});
			btn_Mcancel.setBounds(391, 181, 56, 40);
		}
		return btn_Mcancel;
	}

	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.setBounds(0, 15, 471, 656);
			tabbedPane.setBorder(null);
			tabbedPane.addTab("관리자 입력", null, getManager(), null);
			tabbedPane.addTab("수강생 입력", null, getStudent(), null);
		}
		return tabbedPane;
	}

	private JPanel getStudent() {
		if (student == null) {
			student = new JPanel();
			student.setBackground(SystemColor.text);
			student.setLayout(null);
			student.add(getPanel_2());
			student.add(getBtnWjwkd());
			student.add(getButton());
			student.add(getButton_2());
			student.add(getPanel_7());
			student.add(getPanel_3_1());
			student.add(getPanel_10());
			student.add(getPanel());
			student.add(getBtnExcel());
			student.add(getBtnFS());
			student.add(getBtnNewButton());
			student.add(getLblstatus());
			student.add(getButton_1());
		}
		return student;
	}

	private JPanel getManager() {
		if (manager == null) {
			manager = new JPanel();
			manager.addComponentListener(new ComponentAdapter() {
				@Override
				public void componentShown(ComponentEvent arg0) {
					flag = true;
					foldbtn();
					btnFS.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\down.png"));
				}
			});
			manager.setBorder(null);
			manager.setBackground(SystemColor.text);
			manager.setLayout(null);
			manager.add(getPanel_4());
			manager.add(getPanel_5());
			manager.add(getBtn_Mok());
			manager.add(getBtn_Mcancel());
			manager.add(getButton_3());
			manager.add(getPanel_9());
		}
		return manager;
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("과   정   명");
			lblNewLabel.setBounds(7, 37, 67, 25);
			lblNewLabel.setHorizontalTextPosition(SwingConstants.LEFT);
			lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		}
		return lblNewLabel;
	}

	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("수 강 생 코 드");
			lblNewLabel_1.setHorizontalTextPosition(SwingConstants.LEFT);
			lblNewLabel_1.setBounds(12, 20, 81, 25);
			lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
		}
		return lblNewLabel_1;
	}

	private JTextField getInputSname() {
		if (inputSname == null) {
			inputSname = new JTextField();
			inputSname.setBorder(new LineBorder(Color.GRAY));
			inputSname.setPreferredSize(new Dimension(6, 25));
			inputSname.setBounds(105, 63, 160, 25);
			inputSname.setColumns(10);
		}
		return inputSname;
	}

	private JButton getButton() {
		if (button == null) {
			button = new JButton("취소");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					reSet();
				}
			});
			button.setBounds(320, 177, 56, 40);
		}
		return button;
	}

	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setBorder(new LineBorder(SystemColor.inactiveCaption));
			panel_2.setBackground(SystemColor.inactiveCaptionBorder);
			panel_2.setBounds(170, 11, 277, 156);
			panel_2.setLayout(null);
			panel_2.add(getInputSname());
			panel_2.add(getTextField_8());
			panel_2.add(getPanel_8());
			panel_2.add(getLabel_11_1());
			panel_2.add(getLabel_12_1());
			panel_2.add(getLblNewLabel_1());
		}
		return panel_2;
	}

	private JTextField getTextField_8() {
		if (inputScode == null) {
			inputScode = new JTextField();
			inputScode.setBackground(SystemColor.inactiveCaption);
			inputScode.setFont(new Font("굴림", Font.BOLD, 12));
			inputScode.setHorizontalAlignment(SwingConstants.CENTER);
			inputScode.setBorder(new LineBorder(Color.GRAY));
			inputScode.setPreferredSize(new Dimension(6, 25));
			inputScode.setEditable(false);
			inputScode.setText("A3");
			inputScode.setColumns(10);
			inputScode.setBounds(105, 19, 160, 25);
		}
		return inputScode;
	}

	private JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setBorder(new LineBorder(SystemColor.inactiveCaption));
			panel_4.setBackground(SystemColor.inactiveCaptionBorder);
			panel_4.setLayout(null);
			panel_4.setBounds(170, 15, 277, 156);
			panel_4.add(getLabel());
			panel_4.add(getLabel_1());
			panel_4.add(getLabel_2());
			panel_4.add(getLabel_3());
			panel_4.add(getInputMname());
			panel_4.add(getInputMcode());
			panel_4.add(getPanel_6());
			panel_4.add(getInputMpassword());
		}
		return panel_4;
	}

	private JTextField getInputMph1() {
		if (inputMph1 == null) {
			inputMph1 = new JTextField();
			inputMph1.setHorizontalAlignment(SwingConstants.CENTER);
			inputMph1.setBorder(new LineBorder(Color.GRAY));
			inputMph1.setBounds(0, 1, 37, 25);
			inputMph1.setColumns(10);
		}
		return inputMph1;
	}

	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("암             호");
			label.setHorizontalTextPosition(SwingConstants.LEFT);
			label.setHorizontalAlignment(SwingConstants.LEFT);
			label.setBounds(12, 119, 81, 25);
		}
		return label;
	}

	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("연     락     처");
			label_1.setHorizontalTextPosition(SwingConstants.LEFT);
			label_1.setHorizontalAlignment(SwingConstants.LEFT);
			label_1.setBounds(12, 83, 81, 25);
		}
		return label_1;
	}

	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("성             명");
			label_2.setHorizontalTextPosition(SwingConstants.LEFT);
			label_2.setHorizontalAlignment(SwingConstants.LEFT);
			label_2.setBounds(12, 47, 81, 25);
		}
		return label_2;
	}

	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("관 리 자 코 드");
			label_3.setHorizontalTextPosition(SwingConstants.LEFT);
			label_3.setHorizontalAlignment(SwingConstants.LEFT);
			label_3.setBounds(12, 11, 81, 25);
		}
		return label_3;
	}

	private JTextField getInputMname() {
		if (inputMname == null) {
			inputMname = new JTextField();
			inputMname.setHorizontalAlignment(SwingConstants.LEFT);
			inputMname.setBorder(new LineBorder(Color.GRAY));
			inputMname.setColumns(10);
			inputMname.setBounds(105, 45, 160, 25);
		}
		return inputMname;
	}

	private JTextField getInputMcode() {
		if (inputMcode == null) {
			inputMcode = new JTextField();
			inputMcode.setBackground(SystemColor.inactiveCaption);
			inputMcode.setFont(new Font("굴림", Font.BOLD, 12));
			inputMcode.setHorizontalAlignment(SwingConstants.CENTER);
			inputMcode.setBorder(new LineBorder(Color.GRAY));
			inputMcode.setEditable(false);
			inputMcode.setText("A2");
			inputMcode.setColumns(10);
			inputMcode.setBounds(105, 10, 160, 25);
		}
		return inputMcode;
	}

	private JLabel getTxtLogo2() {
		if (txtLogo2 == null) {
			txtLogo2 = new JLabel("");
			txtLogo2.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\img.jpg"));
			txtLogo2.setBounds(20, 10, 100, 100);
			txtLogo2.setHorizontalAlignment(SwingConstants.CENTER);
			txtLogo2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null,
					null, null));
		}
		return txtLogo2;
	}

	private JButton getBtn_Add() {
		if (btn_Add == null) {
			btn_Add = new JButton("사진추가");
			btn_Add.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					logo();
				}
			});
			btn_Add.setBounds(20, 116, 100, 30);
		}
		return btn_Add;
	}

	private JPanel getPanel_5() {
		if (panel_5 == null) {
			panel_5 = new JPanel();
			panel_5.setBorder(UIManager.getBorder("TextField.border"));
			panel_5.setBounds(160, 16, 2, 156);
		}
		return panel_5;
	}

	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("");
			label_6.setBounds(78, 5, 0, 0);
			label_6.setHorizontalAlignment(SwingConstants.RIGHT);
		}
		return label_6;
	}

	private JLabel getLabel_7() {
		if (label_7 == null) {
			label_7 = new JLabel("등   록   자");
			label_7.setBounds(7, 6, 67, 25);
			label_7.setHorizontalTextPosition(SwingConstants.CENTER);
			label_7.setHorizontalAlignment(SwingConstants.LEFT);
		}
		return label_7;
	}

	private JTextField getInputSdate() {
		if (inputSdate == null) {
			inputSdate = new JTextField();
			inputSdate.setBounds(372, 10, 87, 25);
			inputSdate.setHorizontalAlignment(SwingConstants.CENTER);
			inputSdate.setBorder(new LineBorder(Color.GRAY));
			inputSdate.setBackground(SystemColor.inactiveCaption);
			inputSdate.setPreferredSize(new Dimension(6, 25));
			inputSdate.setEditable(false);
			inputSdate.setColumns(10);
		}
		return inputSdate;
	}

	private JComboBox getCb_Scodename() {
		if (cb_Scodename == null) {
			cb_Scodename = new JComboBox();
			cb_Scodename.setModel(new DefaultComboBoxModel(new String[] {"선택"}));
			cb_Scodename.setBounds(86, 37, 121, 25);
			cb_Scodename.setBorder(null);

			String[] t = { "전체", "수강생", "관리자", "기수" };
		}
		return cb_Scodename;
	}

	private JComboBox getCb_rgname() {
		if (cb_rgname == null) {
			cb_rgname = new JComboBox();
			cb_rgname.setModel(new DefaultComboBoxModel(new String[] {"선택"}));
			cb_rgname.setBorder(null);
			cb_rgname.setBounds(86, 6, 121, 25);
		}
		return cb_rgname;
	}

	private JButton getButton_2() {
		if (button_2 == null) {
			button_2 = new JButton("닫기");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					setVisible(false);
				}
			});
			button_2.setBounds(391, 177, 56, 40);
		}
		return button_2;
	}

	private JButton getButton_3() {
		if (button_3 == null) {
			button_3 = new JButton("취소");
			button_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					reSet();
				}
			});
			button_3.setBounds(329, 181, 56, 40);
		}
		return button_3;
	}

	private JTextField getInputMph2() {
		if (inputMph2 == null) {
			inputMph2 = new JTextField();
			inputMph2.setHorizontalAlignment(SwingConstants.CENTER);
			inputMph2.setBorder(new LineBorder(Color.GRAY));
			inputMph2.setBounds(50, 1, 47, 25);
			inputMph2.setText("");
			inputMph2.setColumns(10);
		}
		return inputMph2;
	}

	private JTextField getInputMph3() {
		if (inputMph3 == null) {
			inputMph3 = new JTextField();
			inputMph3.setHorizontalAlignment(SwingConstants.CENTER);
			inputMph3.setBorder(new LineBorder(Color.GRAY));
			inputMph3.setBounds(110, 1, 50, 25);
			inputMph3.setText("");
			inputMph3.setColumns(10);
		}
		return inputMph3;
	}

	private JLabel getLblNewLabel_4() {
		if (lblNewLabel_4 == null) {
			lblNewLabel_4 = new JLabel("-");
			lblNewLabel_4.setBounds(37, 1, 13, 25);
			lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return lblNewLabel_4;
	}

	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("-");
			label_4.setBounds(97, 1, 13, 25);
			label_4.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return label_4;
	}

	private JPanel getPanel_6() {
		if (panel_6 == null) {
			panel_6 = new JPanel();
			panel_6.setBackground(SystemColor.inactiveCaptionBorder);
			panel_6.setBounds(105, 80, 160, 27);
			panel_6.setLayout(null);
			panel_6.add(getLabel_6());
			panel_6.add(getInputMph1());
			panel_6.add(getInputMph2());
			panel_6.add(getInputMph3());
			panel_6.add(getLblNewLabel_4());
			panel_6.add(getLabel_4());
		}
		return panel_6;
	}

	private JPanel getPanel_8() {
		if (panel_8 == null) {
			panel_8 = new JPanel();
			panel_8.setBackground(SystemColor.inactiveCaptionBorder);
			panel_8.setLayout(null);
			panel_8.setBounds(105, 107, 157, 27);
			panel_8.add(getLabel_13());
			panel_8.add(getInputSph1());
			panel_8.add(getLabel_14());
			panel_8.add(getInputSph2());
			panel_8.add(getLabel_15());
			panel_8.add(getInputSph3());
		}
		return panel_8;
	}

	private JLabel getLabel_13() {
		if (label_13 == null) {
			label_13 = new JLabel("");
			label_13.setHorizontalAlignment(SwingConstants.RIGHT);
			label_13.setBounds(78, 5, 0, 0);
		}
		return label_13;
	}

	private JTextField getInputSph1() {
		if (inputSph1 == null) {
			inputSph1 = new JTextField();
			inputSph1.setBorder(new LineBorder(Color.GRAY));
			inputSph1.setText("");
			inputSph1.setColumns(10);
			inputSph1.setBounds(0, 1, 37, 25);
		}
		return inputSph1;
	}

	private JLabel getLabel_14() {
		if (label_14 == null) {
			label_14 = new JLabel("-");
			label_14.setHorizontalAlignment(SwingConstants.CENTER);
			label_14.setBounds(37, 1, 13, 25);
		}
		return label_14;
	}

	private JTextField getInputSph2() {
		if (inputSph2 == null) {
			inputSph2 = new JTextField();
			inputSph2.setBorder(new LineBorder(Color.GRAY));
			inputSph2.setText("");
			inputSph2.setColumns(10);
			inputSph2.setBounds(50, 1, 47, 25);
		}
		return inputSph2;
	}

	private JLabel getLabel_15() {
		if (label_15 == null) {
			label_15 = new JLabel("-");
			label_15.setHorizontalAlignment(SwingConstants.CENTER);
			label_15.setBounds(97, 1, 13, 25);
		}
		return label_15;
	}

	private JTextField getInputSph3() {
		if (inputSph3 == null) {
			inputSph3 = new JTextField();
			inputSph3.setBorder(new LineBorder(Color.GRAY));
			inputSph3.setText("");
			inputSph3.setColumns(10);
			inputSph3.setBounds(110, 1, 47, 25);
		}
		return inputSph3;
	}

	private JPanel getPanel_9() {
		if (panel_9 == null) {
			panel_9 = new JPanel();
			panel_9.setBorder(new LineBorder(SystemColor.inactiveCaption));
			panel_9.setBackground(SystemColor.inactiveCaptionBorder);
			panel_9.setBounds(12, 15, 140, 156);
			panel_9.setLayout(null);
			panel_9.add(getTxtLogo2());
			panel_9.add(getBtn_Add());
		}
		return panel_9;
	}

	private JPasswordField getInputMpassword() {
		if (inputMpassword == null) {
			inputMpassword = new JPasswordField();
			inputMpassword.setHorizontalAlignment(SwingConstants.LEFT);
			inputMpassword.setBorder(new LineBorder(Color.GRAY));
			inputMpassword.setEchoChar('*');
			inputMpassword.setBounds(105, 121, 160, 25);
		}
		return inputMpassword;
	}

	private JLabel getLabel_11_1() {
		if (label_11 == null) {
			label_11 = new JLabel("연     락     처");
			label_11.setHorizontalTextPosition(SwingConstants.LEFT);
			label_11.setHorizontalAlignment(SwingConstants.LEFT);
			label_11.setBounds(12, 110, 81, 25);
		}
		return label_11;
	}

	private JLabel getLabel_12_1() {
		if (label_12 == null) {
			label_12 = new JLabel("성             명");
			label_12.setHorizontalTextPosition(SwingConstants.LEFT);
			label_12.setHorizontalAlignment(SwingConstants.LEFT);
			label_12.setBounds(12, 65, 81, 25);
		}
		return label_12;
	}

	private JLabel getLabel_8_1() {
		if (label_8 == null) {
			label_8 = new JLabel("등 록 일");
			label_8.setBounds(312, 10, 58, 25);
			label_8.setHorizontalTextPosition(SwingConstants.CENTER);
			label_8.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return label_8;
	}

	private JPanel getPanel_7() {
		if (panel_7 == null) {
			panel_7 = new JPanel();
			panel_7.setBorder(new LineBorder(SystemColor.inactiveCaption));
			panel_7.setLayout(null);
			panel_7.setBackground(SystemColor.inactiveCaptionBorder);
			panel_7.setBounds(12, 11, 140, 156);
			panel_7.add(getLabel_5_1());
			panel_7.add(getButton_4());
		}
		return panel_7;
	}

	private JLabel getLabel_5_1() {
		if (txtLogo1 == null) {
			txtLogo1 = new JLabel("");
			txtLogo1.setIcon(new ImageIcon("C:\\workspace\\svn_bookrent1\\ImageFolder\\img.jpg"));
			txtLogo1.setHorizontalAlignment(SwingConstants.CENTER);
			txtLogo1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null,
					null, null));
			txtLogo1.setBounds(20, 10, 100, 100);
		}
		return txtLogo1;
	}

	private JButton getButton_4() {
		if (button_4 == null) {
			button_4 = new JButton("사진추가");
			button_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					logo2();
				}
			});
			button_4.setBounds(20, 116, 100, 30);
		}
		return button_4;
	}

	private JPanel getPanel_3_1() {
		if (panel_3 == null) {
			panel_3 = new JPanel();
			panel_3.setBorder(UIManager.getBorder("TextField.border"));
			panel_3.setBounds(160, 10, 2, 156);
		}
		return panel_3;
	}

	private JPanel getPanel_10() {
		if (panel_10 == null) {
			panel_10 = new JPanel();
			panel_10.setBackground(Color.WHITE);
			panel_10.setBounds(0, 257, 466, 330);
			panel_10.setLayout(new BorderLayout(0, 0));
			panel_10.add(getScrollPane());
		}
		return panel_10;
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBackground(Color.WHITE);
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}

	private JTable getTable() {
		if (table == null) {
			table = new JTable();
		}
		return table;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("Excel로 저장");
			btnNewButton.setBounds(340, 591, 117, 30);
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					
					if(count==0){
						JOptionPane.showMessageDialog(null, "선택된 데이터가 없습니다.");
						 return;
					}
					
					
					if(cb_rgname.getSelectedIndex()==0){
						JOptionPane.showMessageDialog(null, "등록자를 선택해주세요.");
						return;
					}else if(cb_Scodename.getSelectedIndex()==0){
						JOptionPane.showMessageDialog(null, "수강명을 선택해주세요.");
						return;
					}
					
					
					int a = JOptionPane.showConfirmDialog(null,
							"선택된 목록의 데이터를 저장하시겠습니까?");
					if (a == JOptionPane.OK_OPTION) {
						
						exinsert();
						lblstatus.setText("");
						JOptionPane.showMessageDialog(null, "저장되었습니다.");
						//업데이트로 바로 보내기
						if (mn.mUpdate != null)
							mn.mUpdate.MemSearch();
						//찾기
						
						if (model.getRowCount() > 0) { // 행의 수
							for (int i = model.getRowCount() - 1; i > -1; i--) {
								model.removeRow(i);// 테이블을 초기화
							}
						} else {
							return;
						}
					}

				}
			});
		}
		return btnNewButton;
	}

	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(SystemColor.inactiveCaptionBorder);
			panel.setBorder(new LineBorder(SystemColor.inactiveCaption));
			panel.setBounds(12, 179, 221, 70);
			panel.setLayout(null);
			panel.add(getLabel_7());
			panel.add(getCb_rgname());
			panel.add(getCb_Scodename());
			panel.add(getLblNewLabel());
		}
		return panel;
	}

	private JLabel getLblstatus() {
		if (lblstatus == null) {
			lblstatus = new JLabel("New label");
			lblstatus.setInheritsPopupMenu(false);
			lblstatus.setBounds(12, 597, 241, 20);
		}
		return lblstatus;
	}
	private JButton getButton_1() {
		if (button_1 == null) {
			button_1 = new JButton("선택 해제");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					lblstatus.setText("");
					if (model.getRowCount() > 0) { // 행의 수
						for (int i = model.getRowCount() - 1; i > -1; i--) {
							model.removeRow(i);// 테이블을 초기화
						}
					} else {
						return;
					}
				}
			});
			button_1.setBounds(245, 591, 87, 30);
		}
		return button_1;
	}
}
